from django.core.validators import MinValueValidator
from django.db import models

# Create your models here.
class User(models.Model):
    username=models.CharField(max_length=255,unique=True,null=False)
    password=models.CharField(max_length=255,null=False)
    email=models.CharField(max_length=255,unique=True,null=False)

class Book(models.Model):
    isbn=models.CharField(max_length=255,primary_key=True)
    book_name=models.CharField(max_length=255,null=False)
    author=models.CharField(max_length=255,null=False)
    publish_date=models.DateField(null=False)
    stock=models.IntegerField(null=False,validators=[MinValueValidator(0)])

class BorrowRecord(models.Model):
    user_id=models.ForeignKey(User,on_delete=models.CASCADE,related_name='BorrowRecord')
    isbn=models.ForeignKey(Book,on_delete=models.CASCADE,related_name='BorrowRecord')
    borrow_date=models.DateField(null=False)
    return_date=models.DateField(null=True)